﻿using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;

namespace HECore.NLogWebApi
{
    public class RequestTraceAttribute: TypeFilterAttribute
    {
        public RequestTraceAttribute() :base(typeof(RequestTraceActionFilter)){ }
    }

    public class RequestTraceActionFilter : IActionFilter
    {
        private readonly ILogger<RequestTraceActionFilter> _logger;
        public RequestTraceActionFilter(ILogger<RequestTraceActionFilter> logger) { _logger = logger; }

        public void OnActionExecuted(ActionExecutedContext context) { }

        public void OnActionExecuting(ActionExecutingContext context) { _logger.LogTrace(context.HttpContext.Request.Path); }
    }
}
